package org.jeecg.modules.friends.dao.impl;

import java.util.Collection;
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.jeecg.modules.friends.condition.InvitedUserCondition;
import org.jeecg.modules.friends.mapper.ext.InvitedUserDOExtMapper;
import org.jeecg.modules.friends.model.InvitedUserDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import jnr.ffi.annotations.In;

@Service
public class InvitedUserDAOImpl implements org.jeecg.modules.friends.dao.InvitedUserDAO {
    @Autowired
    private InvitedUserDOExtMapper invitedUserDOExtMapper;

    @Override
    public void insert(InvitedUserDO invitedUserDO) {
        invitedUserDOExtMapper.insert(invitedUserDO);
    }

    @Override
    public List<InvitedUserDO> queryByUserId(Long userId) {
        InvitedUserCondition condition = new InvitedUserCondition();
        InvitedUserCondition.Criteria criteria = condition.createCriteria();
        criteria.andUserIdEqualTo(userId);
        return invitedUserDOExtMapper.selectByCondition(condition);
    }

    @Override
    public InvitedUserDO queryByInvitedUserId(Long userId) {
        InvitedUserCondition condition = new InvitedUserCondition();
        InvitedUserCondition.Criteria criteria = condition.createCriteria();
        criteria.andInvitedUserIdEqualTo(userId);
        List<InvitedUserDO> invitedUserDOS = invitedUserDOExtMapper.selectByCondition(condition);
        return CollectionUtils.isNotEmpty(invitedUserDOS) ? invitedUserDOS.get(0) : null;
    }

    @Override
    public void deleteByUserId(Long userId) {
        InvitedUserCondition condition = new InvitedUserCondition();
        InvitedUserCondition.Criteria criteria = condition.createCriteria();
        criteria.andInvitedUserIdEqualTo(userId);
        invitedUserDOExtMapper.deleteByCondition(condition);
    }

    @Override
    public void update(InvitedUserDO invitedUserDO) {
        invitedUserDOExtMapper.updateByPrimaryKey(invitedUserDO);
    }
}